﻿#include "CPdfRptRestAiOperBase.h"
#include "CGlobal.h"
#include "cimagedownloader.h"
#include "CPdfRptBase.h"

CPdfRptRestAiOperBase::CPdfRptRestAiOperBase(CPdfRptTool *pPdfRptTool, QObject *parent)
	: QObject(parent)
{
	m_pPdfRptTool = pPdfRptTool;
}

CPdfRptRestAiOperBase::~CPdfRptRestAiOperBase()
{

}

//绘制其他AI检测综述表格
bool CPdfRptRestAiOperBase::drawRestAiOverviewForm(double &dStartRow, double &dStartCol, CAllPdfRptDataInfo &dataInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 6;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev24Bold, enPdfRptPenBlack);//设置字体和画笔等级
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 4, 2, A2T("AI检测"), painter, printer, sErrMsg);//绘制表格附带文字-->表名称(皮带纠偏)

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测日期"), painter, printer, sErrMsg);//绘制表格附带文字-->检测日期
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, dataInfo.extraAiDataInfo.m_sDetTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测日期

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测开始时间"), painter, printer, sErrMsg);//绘制表格附带文字-->检测开始时间
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, dataInfo.extraAiDataInfo.m_sDetStartTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测开始时间

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测结束时间"), painter, printer, sErrMsg);//绘制表格附带文字-->检测结束时间
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, dataInfo.extraAiDataInfo.m_sDetEndTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测结束时间

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警总项数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nAlmCount > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, QString::number(dataInfo.extraAiDataInfo.m_nAlmCount), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级
	
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 2, A2T("安全帽反光衣报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nSafetyHelmet > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 2, QString::number(dataInfo.extraAiDataInfo.m_nSafetyHelmet), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 2, A2T("抽烟打电话报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nSmokeMakeCall > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 2, QString::number(dataInfo.extraAiDataInfo.m_nSmokeMakeCall), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("煤流量报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nCoalFlow > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nCoalFlow), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("皮带异物报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nBeltForeign > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nBeltForeign), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("大块煤报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nLargeCoal > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nLargeCoal), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("皮带跑偏报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nBeltDeviation > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nBeltDeviation), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("烟雾火点报警数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	if (dataInfo.extraAiDataInfo.m_nSmokeFire > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nSmokeFire), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("测温报警数"), painter, printer, sErrMsg);//绘制表格附带文字
	if (dataInfo.extraAiDataInfo.m_nTemp > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nTemp), painter, printer, sErrMsg);//绘制表格附带文字
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("周界防范报警数"), painter, printer, sErrMsg);//绘制表格附带文字
	if (dataInfo.extraAiDataInfo.m_nPerimeter > 0)
	{
		m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenRed);//设置字体和画笔等级
	}
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(dataInfo.extraAiDataInfo.m_nPerimeter), painter, printer, sErrMsg);//绘制表格附带文字
	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T(""), painter, printer, sErrMsg);//绘制表格附带文字
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T(""), painter, printer, sErrMsg);//绘制表格附带文字
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("备注"), painter, printer, sErrMsg);//绘制表格附带文字-->备注
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, A2T(""), painter, printer, sErrMsg);//绘制表格附带文字
	return true;
}

//绘制其他AI检测所有报警详情
bool CPdfRptRestAiOperBase::drawRestAiAllAlmDes(double &dStartRow, double &dStartCol, CAllPdfRptDataInfo &dataInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	//遍历Map容器
	int nIndexAi = 0;
	for (QMap<QString, QVector<SPdfExtraAiAlmInfo>>::iterator i = dataInfo.extraAiDataInfo.m_mapExtraAiInfo.begin(); i != dataInfo.extraAiDataInfo.m_mapExtraAiInfo.end(); i++)
	{
		QVector<SPdfExtraAiAlmInfo> vecTe = i.value();
		//遍历这个类型的所有报警
		for (int j = 0; j < vecTe.size(); j++)
		{
			if (0 == nIndexAi)
			{
				printer.newPage();//添加新的一页 第一个其他AI检测报警需强制换页开始显示
				dStartRow = 0;
				dStartCol = 0;

				//绘制详述表头
				drawRestAiAlmDesHeader(dStartRow, dStartCol, painter, printer, sErrMsg);
			}

			drawRestAiSingAlmDes(dStartRow, dStartCol, nIndexAi, i.key(), vecTe[j], painter, printer, sErrMsg);//绘制单个其他AI检测报警详情(不包含表头)
			dStartRow += 1;//间隔一行再画下一组
			nIndexAi++;
		}
	}
	return true;
}
//绘制单个其他AI检测报警详情(不包含表头)
bool CPdfRptRestAiOperBase::drawRestAiSingAlmDes(double &dStartRow, double &dStartCol, int nAlmIdex, QString sDetTypeName, SPdfExtraAiAlmInfo &sglAlmInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 11;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev13, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警序号"), painter, printer, sErrMsg);//绘制表格附带文字-->报警序号
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(nAlmIdex + 1), painter, printer, sErrMsg);//绘制表格附带文字-->报警序号

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警时间"), painter, printer, sErrMsg);//绘制表格附带文字-->报警时间
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sAlmTime, painter, printer, sErrMsg);//绘制表格附带文字-->报警时间

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("摄像头名"), painter, printer, sErrMsg);//绘制表格附带文字-->摄像头名
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sCamerName, painter, printer, sErrMsg);//绘制表格附带文字-->摄像头名

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("摄像头IP"), painter, printer, sErrMsg);//绘制表格附带文字-->摄像头IP
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sCamerIp, painter, printer, sErrMsg);//绘制表格附带文字-->摄像头IP

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警事件"), painter, printer, sErrMsg);//绘制表格附带文字-->报警事件
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sEventType, painter, printer, sErrMsg);//绘制表格附带文字-->报警事件

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警等级"), painter, printer, sErrMsg);//绘制表格附带文字-->报警等级
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sAlarmLevel, painter, printer, sErrMsg);//绘制表格附带文字-->报警等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("是否确认"), painter, printer, sErrMsg);//绘制表格附带文字-->是否确认
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.sIsConfrim, painter, printer, sErrMsg);//绘制表格附带文字-->是否确认
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 2, 1, A2T(""), painter, printer, sErrMsg);//绘制表格附带文字-->是否确认

	//绘制报警图片
	//先绘制左侧合并的单元格
	double dTempStartRow = dStartRow;
	double dTempStartCol = dStartCol;
	m_pPdfRptTool->drawFormAttachText(dTempStartRow, dTempStartCol, 1, 9, A2T("报警图片"), painter, printer, sErrMsg);
	dStartCol += 1;
	//下载图片
	QString sHttpPicUrl = sglAlmInfo.sUrl;
	CImageDownloader downPic(sHttpPicUrl, sglAlmInfo.sCamerUser, sglAlmInfo.sCamerPassWd);
	QPixmap pixmapNow;
	if (sHttpPicUrl.size() > 0)
	{
		downPic.getNewDlPixmap(pixmapNow);
	}
	m_pPdfRptTool->drawFormAttachPic(dStartRow, dStartCol, 3, 9, pixmapNow, painter, printer, sErrMsg);
	return true;
}

//绘制其他AI检测报警详情的表头
bool CPdfRptRestAiOperBase::drawRestAiAlmDesHeader(double &dStartRow, double &dStartCol, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 2;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev24Bold, enPdfRptPenBlack);//设置字体和画笔等级
	QString sTitle = A2T("%1").arg(A2T("AI检测"));
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 4, 2, sTitle, painter, printer, sErrMsg);//绘制表格附带文字-->表名称(皮带跑偏检测)
}
